/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaAgregarTema.java
 *
 * Created on 30/03/2010, 20:12:43
 */

package vista;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.table.TableColumn;
import vista.util.VentanaNuevaMusicaUtil;

/**
 *
 * @author Marcelo
 */
public class VentanaAgregarTema extends javax.swing.JFrame
{

    private VentanaNuevaMusicaUtil util = new VentanaNuevaMusicaUtil();
    private Collection temas = new ArrayList();
    private VentanaNuevoPerfil nuevoPerfil = new VentanaNuevoPerfil();

    /** Creates new form VentanaAgregarTema */
    public VentanaAgregarTema()
    {
        initComponents();
        this.inicializar();
    }

    public VentanaAgregarTema(VentanaNuevoPerfil nuevoPerfil)
    {
        initComponents();
        this.inicializar();
        this.nuevoPerfil = nuevoPerfil;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableCanales = new javax.swing.JTable();
        jButtonAgregar = new javax.swing.JButton();
        jButtonNuevo = new javax.swing.JButton();
        jButtonSalir = new javax.swing.JButton();

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Agregar Tema");

        jTableCanales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nombre", "Genero", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableCanales.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTableCanalesKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTableCanalesKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTableCanalesKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jTableCanales);

        jButtonAgregar.setText("Agregar");
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jButtonNuevo.setText("Nuevo");
        jButtonNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNuevoActionPerformed(evt);
            }
        });

        jButtonSalir.setText("Salir");
        jButtonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonNuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAgregar)
                    .addComponent(jButtonSalir)
                    .addComponent(jButtonNuevo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTableCanalesKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableCanalesKeyPressed
    {//GEN-HEADEREND:event_jTableCanalesKeyPressed
        // TODO add your handling code here:
}//GEN-LAST:event_jTableCanalesKeyPressed

    private void jTableCanalesKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableCanalesKeyReleased
    {//GEN-HEADEREND:event_jTableCanalesKeyReleased
}//GEN-LAST:event_jTableCanalesKeyReleased

    private void jTableCanalesKeyTyped(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableCanalesKeyTyped
    {//GEN-HEADEREND:event_jTableCanalesKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTableCanalesKeyTyped

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonAgregarActionPerformed
    {//GEN-HEADEREND:event_jButtonAgregarActionPerformed
        this.agregarTema();
        this.dispose();
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    private void jButtonSalirActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonSalirActionPerformed
    {//GEN-HEADEREND:event_jButtonSalirActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButtonSalirActionPerformed

    private void jButtonNuevoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonNuevoActionPerformed
    {//GEN-HEADEREND:event_jButtonNuevoActionPerformed
        // TODO add your handling code here:
        VentanaNuevaMusica ventana = new VentanaNuevaMusica(this);
        ventana.setVisible(true);
    }//GEN-LAST:event_jButtonNuevoActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaAgregarTema().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonNuevo;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableCanales;
    // End of variables declaration//GEN-END:variables

    private void inicializar()
    {
        this.centrar();
        this.ajustarTamanioColumna();
        this.llenarTabla();
    }

    public void llenarTabla()
    {
        this.temas = this.util.traerTodos(jTableCanales, temas);
    }

    private void centrar()
    {
        Dimension pantalla, cuadro;
	pantalla = Toolkit.getDefaultToolkit().getScreenSize();
	cuadro = this.getSize();
	this.setLocation(((pantalla.width - cuadro.width)/2), (pantalla.height - cuadro.height)/2);
    }

    private void ajustarTamanioColumna()
    {
        TableColumn column = null;
        for (int i = 0; i < 4; i++)
        {
            column = jTableCanales.getColumnModel().getColumn(i);
            switch(i)
            {
                case 0:
                        column.setPreferredWidth(43);
                        break;
                case 1:
                        column.setPreferredWidth(138);
                        break;
                case 2:
                        column.setPreferredWidth(91);
                        break;
                case 3:
                        column.setPreferredWidth(28);
                        break;
            }
        }
    }

    private void agregarTema()
    {
        this.util.agregarTemasAPerfil(nuevoPerfil, jTableCanales, temas);
    }


}
